package com.taikang.hmp.hbusiness.diabetes.measure.warn.action.intface;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.taikang.hmp.frame.common.TKException;
import com.taikang.hmp.frame.common.datastructre.Dto;
import com.taikang.hmp.frame.common.datastructre.support.BaseDto;
import com.taikang.hmp.frame.common.datastructre.support.ResponseDto;
import com.taikang.hmp.frame.common.web.action.BaseAction;
import com.taikang.hmp.hbusiness.diabetes.measure.warn.service.IWarnService;

/** 
 * warn action 
 * author:qrp
 * time:2015年7月24日 上午11:16:26
 */
public class WarnAction extends BaseAction{
	private static Logger logger = LoggerFactory.getLogger(WarnAction.class);

	
	private IWarnService warnService;

	public IWarnService getWarnService() {
		return warnService;
	}

	public void setWarnService(IWarnService warnService) {
		this.warnService = warnService;
	}

	public String executeAction()  {
		if ("getWarnList".equals(requestDto.getMethod())) {
			return getWarnList();
		}else if("setWarnState".equals(requestDto.getMethod())){
			return setWarnState();
		}else if("getWarnCount".equals(requestDto.getMethod())){
			return getWarnCount();
		}else{
			throw new TKException("no support method:"+requestDto.getMethod());
		}
	}
	
	/**
	 * 获取提醒消息列表
	 */
	public String getWarnList(){	
		ResponseDto responseDto = new ResponseDto();
		
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		//
		List<Dto> warnList = warnService.getWarnList(paramDto);
		Dto resultDto = new BaseDto();
		resultDto.put("warnlist", warnList);
		responseDto.pushResultDto(resultDto);
		//
		super.setDataMap(responseDto);
		return SUCCESS;
	}
	/**
	 * 提醒消息状态
	 */
	public String setWarnState(){
		ResponseDto responseDto = new ResponseDto();
		
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		//
		warnService.setWarnState(paramDto);
		//
		super.setDataMap(responseDto);
		return SUCCESS;
	}
	/**
	 * 获取提醒消息数量
	 */
	public String getWarnCount(){		
		ResponseDto responseDto = new ResponseDto();
		
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		//
		int warnCount = warnService.getWarnCount(paramDto);
		Dto resultDto = new BaseDto();
		resultDto.put("warncount", warnCount);
		responseDto.pushResultDto(resultDto);
		//
		super.setDataMap(responseDto);
		return SUCCESS;
	}
}
